<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="../css/longon.css">
  <link rel="stylesheet" href="../css/reset.css">
  <link rel="stylesheet" href="../css/logonZhu.css">
</head>

<body>
  <header>
    <div class="top">
      <img src="../image/honor.svg" alt="">
    </div>
  </header>
  <section>
    <div id="con">
      <div class="top">
        <h1>荣耀账号注册</h1>
        <p>已有账号，<a href="#">去登陆 ></a></p>
        
      </div>
      <div id="error"></div>
      <div class="center">
        <div class="one">
          <span>国家或地区</span>
          <b>中国</b>
          <img src="../image/下箭头.png" alt="">
        </div>
        <div class="two">
          <b>+86（中国)</b>
          <select name="" id="" value="">
            <option value=""></option>
            <option value=""></option>
            <option value=""></option>
          </select>
          <span></span>
          <input type="text" placeholder="请输入手机号" class="phone">
          
        </div>
        <div class="three">
          <input type="text" placeholder="短信验证码">
          <a href="">获取验证码</a>
        </div>
        <div class="four">
          <input type="password" placeholder="密码" class="pwd">
          
        </div>
        <div class="five">
          <input type="password" placeholder="确认密码">
        </div>
      </div>
      <div class="bottom">
        <a href="#" class="submit">注册</a>
      </div>

    </div>
  </section>
  <footer>
    <div class="a">
      <a href="#">荣耀账号用户协议</a>
      <span></span>
      <a href="#">关于荣耀账号与隐私的声明</a>
      <span></span>
      <a href="#">常见问题</a>
      <span></span>
      <a href="#">Cookie</a>

    </div>
    <p>版权所有 &copy; 2022 保留一切权利</p>

  </footer>
</body>

</html>
<script src="../js/jQuery.js"></script>
<script>
    let flagName = false;
    let flagPwd = false;
    var flag = {
        flagName:false,
        flagPwd:false
    }
    $(".phone").blur (function() {
        //数字字母下划线,不能少于六位，至多18位
        var regName = /^1[3,4,5,8,9]\d{9}$/;
        if (regName.test(this.value)) {

         $("#error").css({
           display:"block",
           color:"green"
         })
            flagName = true;
        } else {
          $("#error").css({
           display:"block",
           color:"red"
         }).html("手机号格式不正确") ;
            flagName = false;
        }
    }) 
    $(".pwd").blur(function() {
        //数字字母下划线,不能少于六位，至多18位
        var regPwd = /^.{6,}$/;
        if (regPwd.test(this.value)) {
           $("#error").css({
           display:"block",
           color:"green"
         })
            flagPwd = true;
        } else {
          $("#error").css({
           display:"block",
           color:"red"
         }).html("密码格式不正确")  ;
            flagPwd = false;
        }
    })

  $(".submit").click(function () {
    if (flagName ==false && flagPwd == false) {
            
          } else {
               $.get(
                "../goodsAndShoppingCart/checkUser.php",
                {
                  username: $(".phone").val(),
                },
                function (data) {
                  console.log(data);
                  if (data == "0") {
                    alert("用户已注册");
                  } else {
                    //判断成功  插入数据库并注册
                    $.post(
                      "../goodsAndShoppingCart/addUser.php",
                      {
                        username: $(".phone").val(),
                        userpass: $(".pwd").val(),
                      },
                      function (data) {
                        console.log(data);
                        if (data == 1) {
                          console.log(data);
                          // alert("注册成功");
                          location.href = "logonDeng.html";
                        } else if (data == 0) {
                          alert("注册失败");
                        }
                      }
                    );
                  }
                }
              );
          }
  });





</script>